package presentacion;
import Negocio.vectorEntero;
import Negocio.Entero;
import Negocio.Conjunto;
import Negocio.Imagen;
import javax.swing.table.DefaultTableModel;
import java.util.*;
/**
 *
 * @author Estudiante
 */
public class frmConjunto extends javax.swing.JFrame {

    /** Creates new form frmConjunto */
    public frmConjunto() {
        initComponents();
        this.setLocationRelativeTo(null); 
        this.Dimensionar(4);
       
    }
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnUnion = new javax.swing.JButton();
        btnInter = new javax.swing.JButton();
        btnA_B = new javax.swing.JButton();
        btnB_A = new javax.swing.JButton();
        btnDiferencia = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        btnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnUnion.setText("Union (AUB)");
        btnUnion.setMinimumSize(new java.awt.Dimension(537, 319));
        btnUnion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnionActionPerformed(evt);
            }
        });

        btnInter.setText("Intercepcion");
        btnInter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInterActionPerformed(evt);
            }
        });

        btnA_B.setText("A Menor B");
        btnA_B.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnA_BActionPerformed(evt);
            }
        });

        btnB_A.setText("B Menor A");
        btnB_A.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnB_AActionPerformed(evt);
            }
        });

        btnDiferencia.setText("Diferencia Simetrica");
        btnDiferencia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDiferenciaActionPerformed(evt);
            }
        });

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "RES 1", "RES 2", "RES 3", "RES 4", "RES 5", "RES 6", "RES 7", "RES 8"
            }
        ));
        jScrollPane3.setViewportView(jTable3);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jPanel1.setBorder(new javax.swing.border.MatteBorder(null));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 185, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 152, Short.MAX_VALUE)
        );

        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnUnion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnInter)
                        .addGap(18, 18, 18)
                        .addComponent(btnB_A)
                        .addGap(18, 18, 18)
                        .addComponent(btnA_B))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(118, 118, 118)
                        .addComponent(btnDiferencia, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnSalir))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(83, 83, 83)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUnion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnInter)
                    .addComponent(btnB_A)
                    .addComponent(btnA_B))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDiferencia)
                    .addComponent(btnSalir))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDiferenciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDiferenciaActionPerformed
      Conjunto A=new Conjunto();
Conjunto B=new Conjunto();
Conjunto C=new Conjunto();
this.CargarConjuntoA(A);
this.CargarConjuntoB(B);
C=A.Diferencia_Simetrrica(A, B);
MostratConjunto(C); 
        // TODO add your handling code here:
    }//GEN-LAST:event_btnDiferenciaActionPerformed
private void CargarConjuntoA(Conjunto A){
    for(int i=0;i<=3;i++ ){
        Entero Obj=new Entero();
        Obj.setNum(Integer.parseInt(jTable1.getValueAt(0, i).toString()));
        A.Insertar(Obj);
      }
  }

private void CargarConjuntoB(Conjunto B){
    for(int i=0;i<=3;i++ ){
        Entero Obj=new Entero();
        Obj.setNum(Integer.parseInt(jTable2.getValueAt(0, i).toString()));
        B.Insertar(Obj);
     }
}   
private void MostratConjunto(Conjunto C){
    this.DimensionarRes(C.getN());
    for(int i=0;i<=C.getN()-1;i++){
    jTable3.setValueAt( C.LeerVector(i).getNum(),0,i);   
    }
}

    private void btnUnionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnionActionPerformed
Conjunto A=new Conjunto();
Conjunto B=new Conjunto();
Conjunto C=new Conjunto();
this.CargarConjuntoA(A);
this.CargarConjuntoB(B);
C=A.Union(A, B);
MostratConjunto(C); 
Imagen im = new Imagen(jPanel1);
        jPanel1.add(im).repaint();


// TODO add your handling code here:
    }//GEN-LAST:event_btnUnionActionPerformed

    private void btnInterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInterActionPerformed
Conjunto A=new Conjunto();
Conjunto B=new Conjunto();
Conjunto X=new Conjunto();
Conjunto C=new Conjunto();
this.CargarConjuntoA(A);
this.CargarConjuntoB(B);
C=A.interseccion(A, B, X);
MostratConjunto(C);  

//******
      
    }//GEN-LAST:event_btnInterActionPerformed

    private void btnA_BActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnA_BActionPerformed
        Conjunto A=new Conjunto();
Conjunto B=new Conjunto();
Conjunto X=new Conjunto();
Conjunto C=new Conjunto();
this.CargarConjuntoA(A);
this.CargarConjuntoB(B);
C=A.AmenorB(A, B, X);
MostratConjunto(C);  // TODO add your handling code here:
    }//GEN-LAST:event_btnA_BActionPerformed

    private void btnB_AActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnB_AActionPerformed
Conjunto A=new Conjunto();
Conjunto B=new Conjunto();
Conjunto X=new Conjunto();
Conjunto C=new Conjunto();
this.CargarConjuntoA(A);
this.CargarConjuntoB(B);
C=A.BmenorA(A, B, X);
MostratConjunto(C);          
// TODO add your handling code here:
    }//GEN-LAST:event_btnB_AActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        frmPrincipal f1=new frmPrincipal();
        f1.setVisible(true);
        this.setVisible(false);  // TODO add your handling code here:
}//GEN-LAST:event_btnSalirActionPerformed
private void DimensionarRes(int CantidadColumna){
    DefaultTableModel modelo= new DefaultTableModel();
    this.jTable3.setModel(modelo);
       for(int i=0;i<=CantidadColumna-1;i++){
        modelo.addColumn(Integer.toString(i));
       }
    Object[] fila=new Object[1];
    modelo.addRow(fila);
}

    private void Dimensionar(int CantidadColumna){
    DefaultTableModel modelo= new DefaultTableModel();
    this.jTable1.setModel(modelo);
       for(int i=0;i<=CantidadColumna-1;i++){
        modelo.addColumn(Integer.toString(i));
       }
    Object[] fila=new Object[1];
    modelo.addRow(fila);
    
    DefaultTableModel modelo2= new DefaultTableModel();
    this.jTable2.setModel(modelo2);
       for(int i=0;i<=CantidadColumna-1;i++){
        modelo2.addColumn(Integer.toString(i));
       }
    Object[] fila2=new Object[1];
    modelo2.addRow(fila2);
    
}
  private void Cargar(){
     Set a=new TreeSet();
     Set b=new TreeSet();
      for(int i=0;i<=3;i++ ){
         a.add(Integer.parseInt(jTable1.getValueAt(0, i).toString()));
        b.add(Integer.parseInt(jTable2.getValueAt(0, i).toString()));
    }
    
}                                          


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnA_B;
    private javax.swing.JButton btnB_A;
    private javax.swing.JButton btnDiferencia;
    private javax.swing.JButton btnInter;
    private javax.swing.JButton btnSalir;
    private javax.swing.JButton btnUnion;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    // End of variables declaration//GEN-END:variables

    
}
